package com.zhengdongzulin.zuke.app.main.home.map

import androidx.lifecycle.rxLifeScope
import com.lxj.androidktx.livedata.StateLiveData
import com.zhengdongzulin.zuke.app.Api
import com.zhengdongzulin.zuke.app.data.*
import com.zhengdongzulin.zuke.base.BaseViewModel
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

class MapFindHouseVm : BaseViewModel() {

    var get_city_com_list: StateLiveData<MutableList<City>> = StateLiveData()

    fun get_city_com_list() {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.GET_CITY_COM_LIST)
                            .toResponse<MutableList<City>>()
                            .await()
                    get_city_com_list.postValueAndSuccess(r)
                }, {
            assignment(it, get_city_com_list)
        }
        )
    }

    var position_list: StateLiveData<MutableList<ZKMapFindHouseActivity.Sel>> = StateLiveData()

    fun position_list(cityId: String?) {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.POSITION_LIST)
                            .add("cityId", cityId)
                            .toResponse<MutableList<ZKMapFindHouseActivity.Sel>>()
                            .await()
                    position_list.postValueAndSuccess(r)
                }, {
            assignment(it, position_list)
        }
        )
    }

    var dic_list: StateLiveData<MutableList<ZKMapFindHouseActivity.Sel>> = StateLiveData()

    fun dic_list() {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.DIC_LIST)
                            .add("mark", "5045ea9c-c341-446a-ab7b-a635e57f778d")
                            .toResponse<MutableList<ZKMapFindHouseActivity.Sel>>()
                            .await()
                    dic_list.postValueAndSuccess(r)
                }, {
            assignment(it, dic_list)
        }
        )
    }

    var get_geo_house_by_city: StateLiveData<MutableList<MapData1>> = StateLiveData()

    fun get_geo_house_by_city(cityId: String, data: Map<String, Any> = HashMap()) {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.GET_GEO_HOUSE_BY_CITY)
                            .add("cityId", cityId)
                            .add("current", mCurrentPage)
                            .add("size", mPageSize)
                            .addAll(data)
                            .toResponse<MutableList<MapData1>>()
                            .await()
                    get_geo_house_by_city.postValueAndSuccess(r)
                }, {
            assignment(it, get_geo_house_by_city)
        }
        )
    }

    var get_geo_house_by_area: StateLiveData<MutableList<MapData2>> = StateLiveData()

    fun get_geo_house_by_area( data: Map<String, Any> = HashMap()) {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.GET_GEO_HOUSE_BY_AREA)
                            .add("current", mCurrentPage)
                            .add("size", mPageSize)
                            .addAll(data)
                            .toResponse<MutableList<MapData2>>()
                            .await()
                    get_geo_house_by_area.postValueAndSuccess(r)
                }, {
            assignment(it, get_geo_house_by_area)
        }
        )
    }

    var get_geo_house_info: StateLiveData<MutableList<MapData3>> = StateLiveData()

    fun get_geo_house_info(cityId: String, data: Map<String, Any> = HashMap()) {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.GET_GEO_HOUSE_INFO)
                            .add("cityId", cityId)
                            .add("current", mCurrentPage)
                            .add("size", mPageSize)
                            .addAll(data)
                            .toResponse<MutableList<MapData3>>()
                            .await()
                    get_geo_house_info.postValueAndSuccess(r)
                }, {
            assignment(it, get_geo_house_info)
        }
        )
    }

}